home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / g++ / LogNorm.h < prev    next >
C/C++ Source or Header  |  1995-02-06  |  2KB  |  80 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _LogNormal_h
  19. #ifdef __GNUG__
  20. #pragma interface
  21. #pragma cplusplus
  22. #endif
  23. #define _LogNormal_h 
  24.  
  25. #include <Normal.h>
  26.  
  27. class LogNormal: public Normal {
  28. protected:
  29.     double logMean;
  30.     double logVariance;
  31.     void setState();
  32. public:
  33.     LogNormal(double mean, double variance, RNG *gen);
  34.     double mean();
  35.     double mean(double x);
  36.     double variance();
  37.     double variance(double x);
  38.     virtual double operator()();
  39. };
  40.  
  41.  
  42. inline void LogNormal::setState()
  43. {
  44.     double m2 = logMean * logMean;
  45.     pMean = log(m2 / sqrt(logVariance + m2) );
  46. // from ch@heike.informatik.uni-dortmund.de:
  47. // (was   pVariance = log((sqrt(logVariance + m2)/m2 )); )
  48.     pStdDev = sqrt(log((logVariance + m2)/m2 )); 
  49. }
  50.  
  51. inline LogNormal::LogNormal(double mean, double variance, RNG *gen)
  52.     : Normal(mean, variance, gen)
  53. {
  54.     logMean = mean;
  55.     logVariance = variance;
  56.     setState();
  57. }
  58.  
  59. inline double LogNormal::mean() {
  60.     return logMean;
  61. }
  62.  
  63. inline double LogNormal::mean(double x)
  64. {
  65.     double t=logMean; logMean = x; setState();
  66.     return t;
  67. }
  68.  
  69. inline double LogNormal::variance() {
  70.     return logVariance;
  71. }
  72.  
  73. inline double LogNormal::variance(double x)
  74. {
  75.     double t=logVariance; logVariance = x; setState();
  76.     return t;
  77. }
  78.  
  79. #endif
  80.